

import socket

client = socket.socket()

client.connect(('localhost', 9999))

while True:
    cmd = input('>>>').strip()
    if len(cmd)==0: continue
    client.send(cmd.encode('utf-8'))
    cmd_res_size = client.recv(1024)
    print(cmd_res_size)
    client.send('准备好接受了'.encode())
    received_size = 0
    received_data = b''
    while received_size < int(cmd_res_size.decode()) :
        data = client.recv(1024)
        received_size += len(data)
        received_data += data
        # print(data.decode('utf-8', 'ignore'))
    else:
        print('cmd is receive done', received_size)
        print(received_data.decode('utf-8', 'ignore'))

    # cmd_res = cmd_res.decode()
    # print(cmd_res)

client.close()
